package com.jy.wms.service;

import com.jy.wms.common.UUIDUtils;
import com.jy.wms.common.annotions.BaseServiceDescribe;
import com.jy.wms.common.base.BaseService;
import com.jy.wms.dao.WmsProvinceRankingReportMapper;
import com.jy.wms.pojo.WmsProvinceRankingReport;
import com.jy.wms.pojo.WmsProvinceRankingReport1;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class WmsProvinceRankingTimingService extends BaseService<WmsProvinceRankingReportMapper, WmsProvinceRankingReport> {

    private Date date;

    @BaseServiceDescribe(moduleName = "预警定时任务",btnName = "直销省份排名")
    @Transactional
    public Integer ProvincialTimer(){
        //String  ss="2018-03-21";
        WmsProvinceRankingReport wpr = new WmsProvinceRankingReport();
        try {
            //获取当前系统时间
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
            //为获取当前系统时间
            String sj = df.format(System.currentTimeMillis());
            List<WmsProvinceRankingReport1> Sales = dao.baseselect(sj);
            int i = 1;//记录排名
            int sddl = 0;//记录订单量
            int zddl = 0;
            double Ddslbfb = 0;
            int zxse = 0;
            int zddbfb = 0;
            int a=0;
            for (WmsProvinceRankingReport1 user : Sales) {
                //订单量排序
                if (sddl == 0) {
                    sddl = Integer.parseInt(user.getDdl());
                    i++;
                } else {
                    if (Integer.parseInt(user.getDdl()) == sddl) {
                    } else {
                        sddl = Integer.parseInt(user.getDdl());
                        i++;
                    }
                }
                //总计
                if(user.getDdl()!=null){
                    //统计订单量总计
                    int ddL = Integer.parseInt(user.getDdl());
                    zddl +=  ddL++;
                }
                //统计总订单百分比
                double DdslbfB = Double.parseDouble(user.getDdlbfb());
                Ddslbfb +=  DdslbfB++;
                //统计总销售额
                if(user.getXse()!=null){
                    int zxsE = Integer.parseInt(user.getXse());
                    zxse +=  zxsE++;
                }
                if(user.getXsezb()!=null){
                    //统计总销售额百分比
                    int zddbfB = Integer.parseInt(user.getXsezb());
                    zddbfb += zddbfB;
                }
                //保存数据
                user.setDdlpm(sddl + "");
                user.setId(UUIDUtils.uuid());
                user.setDdlzj(zddl);
                user.setDdbfbzj(Ddslbfb+"%");
                user.setSalesVolume(zxse);
                user.setPercentageOfSales(zddbfb+"%");
                //保存数据到数据
                dao.baseInsert(user);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
